package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 黑名单列表
     *
     * @param page
     * @param pagesize
     * @param userId
     */
    @Override
    public IPage<UserInfo> findBlackList(Integer page, Integer pagesize, Long userId) {
        Page<UserInfo> param = new Page<>(page, pagesize);
        return userInfoMapper.findBlackList(param, userId);
    }

    /**
     * 调用api服务，移除黑名单用户(从tb_black_list表中删除一条记录)
     *
     * @param userId      当前用户
     * @param blackUserId 要移除的黑名单用户
     */
    @Override
    public void deleteBlackUser(Long userId, Long blackUserId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("black_user_id", blackUserId);
        blackListMapper.delete(queryWrapper);
    }
}
